from math import log
from constant import DCARYR, DT, C, R, T, Z, Far, G_K_ION
from blink_coeff_matrix import TOTAL_AREA


def get_d_ca_ryr(vm, i_ca_ryr, i_ca_fsr, ca_in, ca_out):
    ica = i_ca_ryr - i_ca_fsr
    vm_new = vm - (1 - G_K_ION) * ica * DT / (C * TOTAL_AREA) * (10.0 ** 11)  # 计算膜电位

    nernst = - R * T / (Z * Far) * log(ca_in / ca_out) * (10.0 ** 3)  # 计算能斯特电位
    f = 1 - vm_new / nernst
    d_ca_ryr = f * DCARYR

    print(vm_new)
    print(nernst)
    print(f)
    print(d_ca_ryr)
    return vm_new, nernst, d_ca_ryr
